﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BO;

namespace m.Website.Ajax
{
    public partial class AjaxListNews : System.Web.UI.Page
    {
        int PageIndex = lib.PageIndex;
        int PageSize = 10;
        //
        int ZoneID = lib.ZoneID;//zone con
        int ParentID = lib.ParentID;//zone to
        //string UrlZone = lib.UrlZone;
        //string UrlP = lib.UrlP;
        string LISTNEWSFORMAT = "<li{5}><a href=\"{0}\" title=\"{2}\"><img src=\"{1}\" alt=\"{2}\" /></a><h4><a href=\"{0}\">{2}</a></h4><span>{4}</span><p>{3}</p></li>";
        string linkSetPage = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            if (ZoneID == 0)
                dt = BO.News.NewsBO.GetListNews(PageSize.ToString(), PageIndex.ToString());
            else
                dt = BO.News.NewsBO.GetListNewsByZone(PageSize.ToString(), PageIndex.ToString(), ZoneID.ToString());
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string newsID = dt.Rows[i][Const.tbNews.id].ToString();
                    string title = Utils.EnCodeString(dt.Rows[i][Const.tbNews.Title].ToString());
                    string href = dt.Rows[i][Const.tbNews.Url].ToString();
                    string avatar = dt.Rows[i][Const.tbNews.Avatar].ToString();
                    string sapo = dt.Rows[i][Const.tbNews.Sapo].ToString();
                    string sTime = DateTime.Parse(dt.Rows[i][Const.tbNews.DistributionDate].ToString()).ToString("dd/MM/yyyy");
                    //ltListNews.Text += string.Format(LISTNEWSFORMAT, href, avatar, title, sapo, sTime, i == 0 ? " class=\"first\"" : "");
                    ltListNews.Text += string.Format(LISTNEWSFORMAT, href, avatar, title, sapo, sTime, "");
                }
            }
            else
            {
                ltListNews.Text = "</br><b>Hiện chuyên mục này chưa có dữ liệu bạn hãy ghé thăm những chuyên mục khác nhé</b>";
            }
        }
    }
}